import { ApiResult, PageResult } from '@/api';
import request from '@/utils/request';

enum API {
  VislogPageList = '/sysLogVis/page',
  ClearVisLog = '/sysLogVis/clear',
  OplogPageList = '/sysLogOp/page',
  ClearOpLog = '/sysLogOp/clear',
  ExlogPageList = '/sysLogEx/page',
  ClearExLog = '/sysLogEx/clear',
  DifflogPageList = '/sysLogDiff/page',
  ClearDiffLog = '/sysLogDiff/clear'
}

// 获取访问日志分页列表
export const getVisLogPageList = async (params?: any) => {
  const res = await request.post<ApiResult<PageResult<any>>>(
    API.VislogPageList,
    { params }
  );
  if (res.data.code === 200) {
    return res.data.result;
  }
  return Promise.reject(new Error(res.data.message));
};
// 清空访问日志
export const clearVisLog = async () => {
  const res = await request.post<ApiResult<any>>(API.ClearVisLog);
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
};
// 获取操作日志分页列表
export const getOpLogPageList = async (params?: any) => {
  const res = await request.post<ApiResult<PageResult<any>>>(API.OplogPageList, {
    params
  });
  if (res.data.code === 200) {
    return res.data.result;
  }
  return Promise.reject(new Error(res.data.message));
};

// 清空操作日志
export const clearOpLog = async () => {
  const res = await request.post<ApiResult<any>>(API.ClearOpLog);
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
};

// 获取异常日志分页列表
export const getExLogPageList = async (params?: any) => {
  const res = await request.post<ApiResult<PageResult<any>>>(API.ExlogPageList, {
    params
  });
  if (res.data.code === 200) {
    return res.data.result;
  }
  return Promise.reject(new Error(res.data.message));
};
// 清空异常日志
export const clearExLog = async () => {
  const res = await request.post<ApiResult<any>>(API.ClearExLog);
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
};

// 获取差异日志分页列表
export const getDiffLogPageList = async (params?: any) => {
  const res = await request.post<ApiResult<PageResult<any>>>(
    API.DifflogPageList,
    {
      params
    }
  );
  if (res.data.code === 200) {
    return res.data.result;
  }
  return Promise.reject(new Error(res.data.message));
};
// 清空差异日志
export const clearDiffLog = async () => {
  const res = await request.post<ApiResult<any>>(API.ClearDiffLog);
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
};
